# coding:utf-8
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon, QScreen
from PySide6.QtWidgets import QApplication

from qfluentwidgets import NavigationItemPosition, SplitFluentWindow, FluentIcon
from resource import OfficeIcon
from .home_interface import HomeInterface
from .word_interface import WordInterface
from .excel_interface import ExcelInterface
from .ppt_interface import PPtInterface
from .pdf_interface import PdfInterface
from .img_interface import ImgInterface


class MainWindow(SplitFluentWindow):

    def __init__(self):
        super().__init__()
        # 创建子接口
        self.homeInterface = HomeInterface(self)
        self.wordInterface = WordInterface(self)
        self.excelInterface = ExcelInterface(self)
        self.pptInterface = PPtInterface(self)
        self.pdfInterface = PdfInterface(self)
        self.imgInterface = ImgInterface(self)

        # 将项目添加到导航界面
        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.homeInterface, FluentIcon.HOME, '首页')
        self.navigationInterface.addSeparator()

        pos = NavigationItemPosition.SCROLL
        self.addSubInterface(self.wordInterface, OfficeIcon.WORD, 'Word', pos)
        self.addSubInterface(self.excelInterface, OfficeIcon.EXCEL5, 'Excel', pos)
        self.addSubInterface(self.pptInterface, OfficeIcon.PPT, 'PPT', pos)
        self.addSubInterface(self.pdfInterface, OfficeIcon.PDF, 'PDF', pos)
        self.addSubInterface(self.imgInterface, OfficeIcon.IMG1, '图片', pos)

        self.navigationInterface.setExpandWidth(300)

    def initWindow(self):
        self.resize(1000, 700)
        self.setWindowIcon(QIcon(OfficeIcon.LOGO.path()))
        self.setWindowTitle('办公工具')
        self.titleBar.setAttribute(Qt.WA_StyledBackground)

        center = QScreen.availableGeometry(QApplication.primaryScreen()).center()
        geo = self.frameGeometry()
        geo.moveCenter(center)
        self.move(geo.topLeft())
